//
//  NumberCell.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/19/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit
import SnapKit


final class NumberCell: UITableViewCell {
    
    private lazy var numberField: ModalElement = {
        let element = ModalElement()
        element.updateUI(value: nil, placeholder: "Номер телефона", withCheckbox: true)
        return element
    }()
    
    public var parent: ModalElementProtocol! {
        didSet {
            numberField.delegate = parent
        }
    }
    
    public var number: NumberViewModel.Number! {
        didSet {
            numberField.updateUI(value: number.phone, withCheckbox: true, customID: number.id)
        }
    }
    
    public var selectedChexBox: Int! {
        didSet {
            if selectedChexBox != number.id {
                numberField.turnOfCheckBox()
            } else {
                numberField.turnOnCheckBox()
            }
        }
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.addViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


extension NumberCell {
    private func addViews () {
        self.contentView.addSubview(numberField)
        numberField.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview().inset(6)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(48)
        }
    }
}
